<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * HITI Web Develop
 *
 * @package     HITI Web Dev  
 * @category    Models
 * @see 		Hiti carts
 * @author      PHUOCNGUYEN - HITI Dev Team
 * @copyright   Copyright (c) 2013, HITI Corp
 */

class Hiti_carts_model extends CI_Model {
	public function __contruct()
	{
		parent::__contruct();
	}

	public function show()
	{
		$lng = $GLOBALS['cfg']['lng'];
		$this->db->query('SET NAMES "LATIN1"');
		$this->db->from('shopping_carts AS c');
		$this->db->select('c.id, c.gia, c.soluong, c.product, t1.name_vn AS kthuoc, t2.name_vn AS color, c.pricelist, p.name_'.$lng.' AS name, p.keyword, p.img, p.hide_tinhtrang, t.name_'.$lng.' AS tinhtrang, n.keyword AS catkey');
		$this->db->join('products AS p', 'p.id = c.product', 'left');
		$this->db->join('product_properties AS t', 't.id = p.tinhtrang', 'left');
		$this->db->join('product_properties AS t1', 't1.id = c.kthuoc', 'left');
		$this->db->join('product_properties AS t2', 't2.id = c.color', 'left');
		$this->db->join('product_categories AS n', 'n.id = p.cat', 'left');
		$this->db->where('c.ip', $this->input->ip_address());
		$this->db->order_by('id desc');
		$query = $this->db->get();
		if ($query->num_rows())
		{
			return $query->result_array();
		}
		else
		{
			return false;
		}
	}

	public function info($code)
	{
		$lng = $GLOBALS['cfg']['lng'];
		$this->db->query('SET NAMES "LATIN1"');
		$this->db->from('orders AS c');
		$this->db->select('c.*');
		$this->db->where('c.ma', $code);
		$query = $this->db->get();
		if ($query->num_rows())
		{
			return $query->row_array();
		}
		else
		{
			return false;
		}
	}

	public function details($code)
	{
		$lng = $GLOBALS['cfg']['lng'];
		$this->db->query('SET NAMES "LATIN1"');
		$this->db->from('orders_details AS c');
		$this->db->select('c.id, c.ma, c.gia, c.soluong, c.proid, c.tongcong, c.pricelist, p.name_'.$lng.' AS name, p.keyword, p.img, p.hide_tinhtrang, t.name_'.$lng.' AS tinhtrang, p.code, n.keyword AS catkey');
		$this->db->join('products AS p', 'p.id = c.proid', 'left');
		$this->db->join('product_properties AS t', 't.id = p.tinhtrang', 'left');
        $this->db->join('product_categories AS n', 'n.id = p.cat', 'left');
		$this->db->where('c.ma', $code);
		$this->db->order_by('id desc');
		$query = $this->db->get();
		if ($query->num_rows())
		{
			return $query->result_array();
		}
		else
		{
			return false;
		}
	}

	public function update_checkout($ma, $data)
	{
		if (!is_array($data))
		{
			return false;
		}
		$this->db->where('ma', $ma);
		$this->db->update('orders', $data);
		return true;
	}

}

/* End of file hiti_carts_model.php */
/* Location: ./application/models/hiti_carts_model.php */